<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数</title>
</head>

<body>
    <script>
        /* (function () {
            console.log("立即调用");
        })(); */

        /*
         //不管传入多少个实际参数，永远都能够计算他们的和
        function add() {
            var sum = 0;
            for (var i = 0; i < arguments.length; i++) {
                sum += arguments[i]
            }
            return sum;
        }
        console.log(add(1, 2),
            add(1, 2, 3),
            add(2),
            add(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); 
            */

        /* console.log(fn);
        console.log(i);
        var i = 1;
        function fn() {
            console.log(2);
        } */

        /*
        function fn(a) {
            return a;
        }
        console.log(fn(1)); 
        */

        /* 
        var age = 10
        function person() {
            age = 100;
            console.log(age);
            var age;
            console.log(age);
        }
        person();
        console.log(age);
        */

        /* 
        console.log(fn(1));
        var fn = function (a) {
            return a;
        };
         */

        /* 
        fn();//2
        var fn = function () {
            console.log(1);
        };
        fn();//1
        function fn() {
            console.log(2);
        }
        var fn;
        fn();//1 
        */

        function fn() {
            console.log(2);
        }
        var fn;
        fn();//2
        fn = function () {
            console.log(1);
        };
        fn();//1
        fn();//1
    </script>
</body>

</html>